package com.example.SocialApplication.activity.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import com.example.SocialApplication.HelperFactory;
import com.example.SocialApplication.R;
import com.example.SocialApplication.adapters.ColorSpectrumAdapter;
import com.example.SocialApplication.db.entity.ColorEntity;

import java.sql.SQLException;
import java.util.List;

public class ColorSpectrumThingDialog extends Dialog {

    private ColorSpectrumThingInterface anInterface;

    public ColorSpectrumThingDialog(Context context, ImageView image, ColorSpectrumThingInterface thingInterface) {
        super(context);
        this.anInterface = thingInterface;

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.color_spectrum_dialog);

        GridView view = (GridView) findViewById(R.id.gridView);

        try {
            List<ColorEntity> list = HelperFactory.getHelper().getColorEntityDAO().queryForAll();
            final ColorSpectrumAdapter adapter = new ColorSpectrumAdapter(getContext(), R.layout.color_spectrum_item, list, image, false);
            view.setAdapter(adapter);
            view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    anInterface.onSpectrumClick(adapter.getItem(position).getBackground());
                }
            });
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
